<template>
<!--  <dialog-editor ref="dialog"></dialog-editor>-->
  <screenshot-upload ref="dialog1"></screenshot-upload>

</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import screenshotUpload from '@/components/screenshotUpload'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor,screenshotUpload},
  data() {
    return {
      stepsConfig: {
        steps: [
          {
            title: '步骤1',
            Attrs: ['productNo', 'modelId',  'clientId','productImageId']
          },
          {
            title: '步骤2',
            Attrs: ['productCategoryId', 'productWeight', 'weightScope', 'productVolume', 'volumeScope', 'volumeRemark',
              'bottleInDiameter', 'bottleOutDiameter','bottleLength','bottleWeight', 'headNeckHeight', 'bottleHeight', 'lengthWeightHeight',
              'productQuestion', 'productAssort', 'deepCategoryList', 'remark']
          },
          {
            title: '步骤3'
          }
        ]
      },
      dataFormConfig: {
        id: {
          hidden: true
        },
        productNo: {
          label: '产品编号',
          placeholder: '请输入产品编号'
        },
        modelId: {
          label: '模具',
          type: 'list',
          filterable: true,
          clearable: true,
          placeholder: '请选择模具',
          list: [],
          isNeedAdd: true,
          addNewItemFunc: this.addNewModel
        },
        clientId: {
          label: '客户名称',
          type: 'list',
          filterable: true,
          clearable: true,
          placeholder: '请选择客户名称',
          list: []
        },
        // boxIdList: {
        //   label: '纸箱',
        //   type: 'list',
        //   selectMultiple: true,
        //   clearable: true,
        //   placeholder: '请选择纸箱',
        //   list: []
        // },
        // clientProductNo: {
        //   label: '客户产品编号',
        //   placeholder: '请输入客户产品编号'
        // },
        productCategoryId: {
          label: '产品分类',
          list: [],
          type: 'list',
          placeholder: '请选择产品分类'
        },
        productWeight: {
          label: '产品克数',
          type: 'number',
          max: 1000,
          default: 0
        },
        weightScope: {
          label: '克重误差(±)',
          type: 'String',
          default: '±'
        },
        productVolume: {
          label: '产品容量(ml)',
          type: 'number',
          max: 1000,
          default: 0
        },
        volumeScope: {
          label: '容量误差(±)',
          type: 'String',
          default: '±'
        },
        volumeRemark: {
          label: '容量备注',
          inputType: 'textarea',
          placeholder: '请输入备注备注'
        },
        productImageId: {
          label: '产品图片',
          attrName: 'productImageId',
          type: 'uploadScreenshot',
          imageType: 'uploadProductImage'
        },
        productDrawingId: {
          label: '产品图纸',
          type: 'uploadImage',
          imageType: 'uploadProductPaper'
        },
        bottleOutDiameter: {
          label: '口径(mm)',
          placeholder: '请输入瓶口外径'
        },
        bottleInDiameter: {
          label: '瓶口内径(mm)',
          placeholder: '请输入瓶口内径'
        },
        bottleLength: {
          label: '瓶长(mm)',
          placeholder: '请输入瓶子长度',
          type: 'number',
          max: 1000,
          default: 0
        },
        bottleWeight: {
          label: '瓶宽(mm)',
          placeholder: '请输入瓶宽',
          type: 'number',
          max: 1000,
          default: 0
        },
        bottleHeight: {
          label: '瓶高(mm)',
          type: 'number',
          max: 1000,
          default: 0
        },
        headNeckHeight: {
          label: '头径高度(mm)',
          type: 'number',
          max: 1000,
          default: 0
        },
        // productAssort: {
        //   label: '组合套',
        //   type: 'switch'
        // },
        // deepCategoryList: {
        //   label: '深加工种类',
        //   placeholder: '请选择深加工种类',
        //   selectMultiple: true,
        //   type: 'list',
        //   clearable: true,
        //   list: []
        // },
        remark: {
          label: '产品备注',
          inputType: 'textarea',
          placeholder: '请输入产品备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    addNewModel() {
      const cb = (newValue) => {
        this.initModelInfoList('modelId')
        this.dataForm.modelId = newValue.id
      }
      this.$parent.openModelInfoDialog(cb)
    },
   async init(id, property, cb) {
      this.dataForm.id = id || 0
      this.initProductCategoryList()
   //   this.initDeepCategoryList('deepCategoryList')
      this.initModelInfoList('modelId')
    await  this.initClientInfoList('clientId')

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        stepsConfig: this.stepsConfig,
        dataRule: this.getNeedDataRule('productNo','status',  'productWeight', 'productVolume',  'bottleLength','bottleWeight','bottleHeight','bottleOutDiameter', 'productDrawingId'),
        initApi: 'productApi/productInfoInfo',
        saveApi: 'productApi/saveProductInfo',
        updateApi: 'productApi/updateProductInfo',
        objectName: 'productInfo',
        submitCallback: cb
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            if (key.startsWith('clientId')) {
              this.dataForm['clientId'] = property[key].clientId
            }else {
              this.dataForm[key] = property[key]
            }
          })
        }
      })
    }
  }
}
</script>
